//
//  ST_SendMsgRightController.swift
//  btvideo
//
//  Created by mac on 2020/5/15.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift
import SnapKit

/**
 聊天会员弹窗
 */
class ST_SendMsgRightController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.width.equalTo(310)
            make.height.equalTo(root_view_height)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
//            .offset(-ScreenHeight/10)
        }
        
        
        root_view.addSubview(bottom_view)
        bottom_view.snp.makeConstraints { (make) in
            make.bottom.right.left.equalToSuperview()
            make.height.equalTo(121)
        }
        root_view.addSubview(top_view)
        top_view.snp.makeConstraints { (make) in
            make.top.right.left.equalToSuperview()
            make.bottom.equalTo(bottom_view.snp.top)
        }
        
        
        
        
        top_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(50)
            make.top.equalToSuperview().offset(27)
            make.centerX.equalToSuperview()
        }
        
        top_view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(cover_image_view.snp.bottom).offset(8)
            make.centerX.equalToSuperview()
        }
        
        
        top_view.addSubview(middle_view)
        middle_view.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(46)
            make.left.equalToSuperview().offset(25)
            make.right.equalToSuperview().offset(-25)
            make.height.equalTo(50)
        }
        
        top_view.addSubview(first_step_image_view)
        first_step_image_view.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(25)
            make.top.equalTo(titleLabel.snp.bottom).offset(10)
            make.width.equalTo(75)
            make.height.equalTo(26)
        }
        
        top_view.addSubview(second_step_image_view)
        second_step_image_view.snp.makeConstraints { (make) in
            make.left.equalTo(first_step_image_view.snp.right).offset(-9)
            make.top.height.equalTo(first_step_image_view)
            make.width.equalTo(115)
        }
        
        bottom_view.addSubview(cancel_btn)
        bottom_view.addSubview(confirm_btn)
        confirm_btn.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 25, left: 53, bottom: 52, right: 47))
        }
        
        
        
        cancel_btn.snp.makeConstraints { (make) in
            make.top.equalTo(confirm_btn.snp.bottom)
            make.width.height.centerX.equalTo(confirm_btn)
        }
        
    }
    
    
//    MARK:- Properties
   @objc var root_view_height = 366.cgFloat
    
    fileprivate lazy var root_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.white
        control.cornerRadius = 20
        control.borderColor = Color.init(hexString: "#979797")
        control.borderWidth = 1
        return control
    }()
    
    fileprivate lazy var top_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.init(hex: 0x42CEDA)
        return control
    }()
    
    fileprivate lazy var bottom_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.white
        return control
    }()
    
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("发送消息权限")
        return control
    }()
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        control.textAlignment = .center
        control.textColor = .white
        control.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
        control.text = "消息的开启与发送需要成为\n伴心会员才能使用"
        return control
    }()
    
    
    
    fileprivate lazy var middle_view:SendMsgRightAlertTipsView = {
        let control = SendMsgRightAlertTipsView()
        return control
    }()
    
    fileprivate lazy var first_step_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("伴心成为会员")
        return control
    }()
    
    fileprivate lazy var second_step_image_view:UIImageView = {
        let control = UIImageView()
        control.image = ST_ImageUtils.imageName("伴心成为会员消息发送")
        return control
    }()
    
////    另一种样式
//    fileprivate lazy var second_step_copy_image_view:UIImageView = {
//        let control = UIImageView()
//        control.image = ST_ImageUtils.imageName("首页_img_添加特质弹窗")
//        return control
//    }()
//
//    fileprivate lazy var thirdly_step_image_view:UIImageView = {
//        let control = UIImageView()
//        control.image = ST_ImageUtils.imageName("首页_img_首页展示弹窗")
//        return control
//    }()
    
    
    
//    fileprivate lazy var content_label:UILabel = {
//        let control = UILabel.init()
//        control.numberOfLines = 0
//        control.textColor = .white
//        control.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium)
//        return control
//    }()
    

    fileprivate lazy var confirm_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 35/2.0
        control.setTitleForAllStates("成为会员")
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.semibold)
        control.setTitleColorForAllStates(UIColor.white)
        control.addTarget(self, action: #selector(confirm_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var cancel_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.clear
//        control.cornerRadius = 36/2.0
        control.setTitleForAllStates("稍后再说")
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular)
        control.setTitleColorForAllStates(UIColor.init(hexString: "#61666F")!)
        control.addTarget(self, action: #selector(cancel_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    
//    MARK: - Public
    
    @objc var confirm_closure:(()->())?
    @objc var cancel_closure:(()->())?
    
}


extension ST_SendMsgRightController{
    
    @objc func confirm_handle(){
        
        
        
        self.dismiss(animated: false) {
            self.confirm_closure?()
        }
        
    }
    
    @objc func cancel_handle(){
        
        self.dismiss(animated: false) {
            self.cancel_closure?()
        }
    }
    
    
}



fileprivate class SendMsgRightAlertTipsView:UIView{
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        self.cornerRadius = 5
        self.borderColor = UIColor.init(white: 1, alpha: 0.3)
        self.borderWidth = 1
        
        self.addSubview(cover_image_view)
        self.addSubview(content_label)
        
        cover_image_view.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(10)
            make.centerY.equalToSuperview()
        }
        content_label.snp.makeConstraints { (make) in
            make.left.equalTo(cover_image_view.snp.right).offset(5)
            make.top.equalToSuperview().offset(9)
            make.bottom.equalToSuperview().offset(-9)
            make.right.equalToSuperview().offset(-7)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("首页_icon_认证示意(弹窗)")!)
        return control
    }()
    
    
    fileprivate lazy var content_label:UILabel = {
        
        let control = UILabel.init()
        
        let attrString = NSMutableAttributedString(string: "伴心保证用户质量，每一个与你进行聊天的用户都是真实付费用户")
        
        let paragh = NSMutableParagraphStyle()
        
        paragh.lineSpacing = 3
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 12),.foregroundColor: UIColor(red: 1, green: 1, blue: 1, alpha: 1),.paragraphStyle:paragh]
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        control.attributedText = attrString
        
        control.numberOfLines = 0
        
        return control
    }()

    
    
}
